//
//  ViewController+Exten.swift
//  CosClub
//
//  Created by 沙睿 on 2020/2/6.
//  Copyright © 2020 ios. All rights reserved.
//

import Foundation
import UIKit

public protocol AnimateShowFromBottom {
    var height: CGFloat {get}
}

public struct AnimateBottom:  AnimateShowFromBottom {
    public var height: CGFloat
    public init(height: CGFloat) {
        self.height = height
    }
}

extension UIViewController {
    public func showView(_ aniBottom: AnimateShowFromBottom) {
        self.view.frame = CGRect(x: 0, y: kScreenHeight, width: kScreenWidth, height: aniBottom.height)
        UIView.animate(withDuration: 0.3, animations: {
            self.view.transform = CGAffineTransform(translationX: 0, y: -aniBottom.height);
        }) { (finish) in
            if !finish {
                self.view.transform = CGAffineTransform(translationX: 0, y: -aniBottom.height);
            }
        }
    }
    
    public func viewDismiss() {
        UIView.animate(withDuration: 0.3, animations: {
            self.view.transform = CGAffineTransform(translationX: 0, y: 0);
        }) { (finish) in
            if !finish {
                self.view.transform = CGAffineTransform(translationX: 0, y: 0);
            }
            self.view.removeFromSuperview()
            self.removeFromParent()
        }
    }
}


